var app = new Vue({
    el: '#upperShelf',
    data () {
        return {
            headerTitle: '搜索商品',
            showType: 0, // 0 商品分类, 1 按商品分类搜索, 2 价格纠错, 3 商品有偿上架, 4 历史
            changeMarketTitle: '', // 选择超市或修改超市
            market: { // 超市名和超市ID
                marketName: '',
                supermarketId: null,
            },
            marketKey: '', // 超市搜索关键字
            marketData: null, // 超市搜索数据
            secondCategoryData: null, // 二级商品分类数据
            thirdCategoryData: null, // 三级商品分类数据
            tabs: null, // 一级商品分类
            secondId: '', // 当前展开的一级分类Id
            thirdId: null, // 当前展开的二级分类Id
            thirdIndex: 0, // 当前展开的二级分类索引
            categoryId: null, // 按分类搜索的当前分类Id
            currentPage: 1,
            totalPage: 2,
            pageSize: 12,
            pullUpLoad: false,
            pullUpLoadThreshold: 0,
            pullUpLoadNoMoreTxt: '没有更多了！',
            key: '', // 按分类搜索的关键字
            barcode: '', // 按分类搜索的条形码
            sortTab: [ // 排序显示
                {
                    title: '综合'
                },
                {
                    title: '价格'
                },
                {
                    title: '价差率'
                }
            ],
            orderType: 'AFFECTEDTIME_DOWN', // 排序 AFFECTEDTIME_DOWN 综合，PRICE_UP 价格升序，PRICE_DOWM 价格降序，SPREAD_DOWM 价差降序
            tabIndex: 0,
            searchData: null, // 按分类搜索的结果数据
            upperShelfParams: { // 有偿上架所传参数
                name: '',
                brand: '',
                price: '',
                specification: '',
                description: '',
                barcode: '',
                priceType: '请选择价格类型',
                startTime: '请选择开始时间',
                endTime: '请选择结束时间',
                file: ''
            },
            showPrice: null, // 表单提交价格
            imageSrc: '', // 表单提交上传图片显示
            btnDisabled: false, // 提交按钮是否可用
            params: { // 价格纠错所传参数
                priceType: '请选择价格类型',
                startTime: '请选择开始时间',
                endTime: '请选择结束时间',
                goodsSkuId: '',
                supermarketId: '',
                price: ''
            },
            correctionGoods: {
                image: '',
                name: '',
                price: '',
                royaltyAmount: null,
                barcode: ''
            },
            historyTabLabel: '有偿上架',
            historyTab: [
                {
                    label: '有偿上架'
                },
                {
                    label: '分享纠错'
                }
            ],
            correctionHistoryData: null,
            upperShelfHistoryData: null,
            historyMarket: { // 超市名和超市ID
                marketName: '全部',
                supermarketId: null,
            },
            historyMarketTitle: '选择超市',
            loop: false,
            autoPlay: false,
            showDots: false,
            slideOptions: {
                click: false,
                listenScroll: true,
                probeType: 3,
                directionLockThreshold: 0
            },
            startTime: '',
            endTime: ''
        }
    },
    watch: {
        marketKey (val) {
            if (val.length > 0) {
                this.pullUpLoad = true
                this.currentPage = 1
                this.getMarketData()
            } else {
                this.marketData = null
                this.pullUpLoad = false
            }
        }
    },
    computed: {
        initialIndex () {
            let index = 0
            index = this.findIndex(this.historyTab, item => item.label === this.historyTabLabel)
            return index
        },
        scrollOptions () {
            return {
                pullUpLoad: this.pullUpLoadObj
            }
        },
        pullUpLoadObj: function() {
            return this.pullUpLoad ? {
                threshold: parseInt(this.pullUpLoadThreshold),
                txt: {
                    noMore: this.pullUpLoadNoMoreTxt
                }
            } : false
        }
    },
    created() {
        let market = JSON.parse(localStorage.getItem('market'))
        if (market) {
            this.changeMarketTitle = '修改超市'
            this.market.marketName = market.marketName
            this.market.supermarketId = market.supermarketId
        } else {
            this.changeMarketTitle = '选择超市'
        }
        this.getFirstCategoryData()
    },
    methods: {
        // 返回
        goback () {
            if (this.showType === 0) {
                window.history.go(-1)
            } else if (this.showType === 1) {
                this.showType = 0
                this.headerTitle = '搜索商品'
                this.key = ''
                this.orderType = 'AFFECTEDTIME_DOWN'
                this.tabIndex = 0
            } else if (this.showType === 2) {
                this.currentPage = 1
                this.pullUpLoad = false
                this.getSearchData()
                this.showType = 1
                this.headerTitle = '商品上架/核查'
                this.correctionInitialize()
            } else if (this.showType === 3) {
                this.currentPage = 1
                this.pullUpLoad = false
                this.getSearchData()
                this.showType = 1
                this.headerTitle = '商品上架/核查'
                this.upperShelfInitialize()
            } else if (this.showType === 4) {
                this.currentPage = 1
                this.pullUpLoad = false
                this.getSearchData()
                this.showType = 1
                this.headerTitle = '商品上架/核查'
                this.startTime = ''
                this.endTime = ''
                this.historyMarket = {
                    marketName: '全部',
                    supermarketId: null,
                }
            }
        },
        findIndex(ary, fn) {
            if (ary.findIndex) {
                return ary.findIndex(fn)
            }
            let index = -1
            ary.some(function (item, i, ary) {
                const ret = fn.call(this, item, i, ary)
                if (ret) {
                    index = i
                    return ret
                }
            })
            return index
        },
        // 点击修改超市弹窗弹出
        changeMarket () {
            this.marketKey = ''
            this.marketData = null
            const choiceMarket = this.$refs.choiceMarket
            choiceMarket.show()
        },
        // 右侧选择超市弹窗无限加载超市列表数据
        marketDataMore () {
            this.currentPage ++
            if(this.currentPage > this.totalPage){
                this.$refs.marketData.forceUpdate()
                return
            }
            this.getMarketData()
        },
        // 右侧选择超市弹窗获取超市列表数据
        getMarketData () {
            Axios.post('area/Supermarket/getSupermarketByKey.do', {
                key: this.marketKey,
                currentPage: this.currentPage,
                pageSize: this.pageSize
            }).then(res => {
                if (res.respCode === 'S') {
                    let list = res.data.data
                    let reg = new RegExp(this.marketKey, 'g')
                    list.forEach(item => {
                        item.name = item.name.replace(reg, '<i>' + this.marketKey +'</i>')
                    })
                    if (this.currentPage === 1) {
                        this.marketData = list
                    } else {
                        this.marketData = this.marketData.concat(list)
                    }
                    this.totalPage = res.data.totalPage

                    if (this.currentPage >= this.totalPage) {
                        this.$refs.marketData.forceUpdate()
                    }
                }
            })
        },
        // 右侧选择超市弹窗选择超市
        choiceMarket (item) {
            let reg = new RegExp('<i>', 'g')
            let reg1 = new RegExp('</i>', 'g')
            item.name = item.name.replace(reg, '')
            item.name = item.name.replace(reg1, '')
            if (this.showType === 4) {
                this.historyMarket.marketName = item.name
                this.historyMarket.supermarketId = item.supermarketId
                this.historyMarketTitle = '修改超市'
                this.currentPage = 1
                this.pullUpLoad = false
                if (this.historyTabLabel === '有偿上架') {
                    this.$refs.upperShelfHistory.scrollTo(0, 0)
                    this.getUpperShelfHistoryData()
                } else if (this.historyTabLabel === '分享纠错') {
                    this.$refs.correctionHistory.scrollTo(0, 0)
                    this.getCorrectionHistoryData()
                }
            } else {
                this.market.marketName = item.name
                this.market.supermarketId = item.supermarketId
                localStorage.setItem("market", JSON.stringify(this.market))
                this.changeMarketTitle = '修改超市'
            }
            const choiceMarket = this.$refs.choiceMarket
            choiceMarket.hide()
            if (this.showType === 1) {
                this.currentPage = 1
                this.pullUpLoad = false
                this.tabIndex = 0
                this.orderType = 'AFFECTEDTIME_DOWN'
                this.$refs.goodsScroll.scrollTo(0, 0, 200, 'linear')
                this.getSearchData()
            }
        },
        // 商品分类一级分类切换
        changeHandler (label) {
            this.secondId = label
            this.getSecondCategoryData()
            this.$nextTick(() => {
                this.$refs.scroll.scrollTo(0, 0)
                this.$refs.scroll.refresh()
            })
        },
        // 商品分类二级分类切换
        changeSecondTab (index, item) {
            if (this.thirdIndex !== index) {
                this.thirdIndex = index
                this.thirdId = item.categoryId
                this.getThirdCategoryData()
                this.$nextTick(() => {
                    this.$refs.scroll.refresh()
                })
            }
        },
        // 获取商品分类一级分类
        getFirstCategoryData () {
            Axios.post('goods/category/showCategory.do', {
                parentId: 893
            }).then(res => {
                if (res.respCode === 'S') {
                    let list = res.data
                    this.secondId = list[0].categoryId
                    this.getSecondCategoryData()
                    this.tabs = list.map(item => {
                        let data = {
                            value: item.categoryId,
                            label: item.name
                        }
                        return data
                    })
                } else {
                    this.toast = this.$createToast({
                        txt: res.errorMsg,
                        type: 'txt',
                        time: 1500
                    }).show()
                }
            })
        },
        // 获取商品分类二级分类
        getSecondCategoryData () {
            Axios.post('goods/category/showCategory.do', {
                parentId: this.secondId
            }).then(res => {
                if (res.respCode === 'S') {
                    let list = res.data
                    this.thirdId = list[0].categoryId
                    this.secondCategoryData = list
                    this.thirdIndex = 0
                    this.getThirdCategoryData()
                } else {
                    this.toast = this.$createToast({
                        txt: res.errorMsg,
                        type: 'txt',
                        time: 1500
                    }).show()
                }
            })
        },
        // 获取商品分类三级分类
        getThirdCategoryData () {
            Axios.post('goods/category/showCategory.do', {
                parentId: this.thirdId
            }).then(res => {
                if (res.respCode === 'S') {
                    let list = res.data
                    this.thirdCategoryData = list
                } else {
                    this.toast = this.$createToast({
                        txt: res.errorMsg,
                        type: 'txt',
                        time: 1500
                    }).show()
                }
            })
        },
        // 点击三级分类跳转至按商品分类搜索
        clickCategory (item) {
            if (this.market.supermarketId) {
                this.showType = 1
                this.headerTitle = '商品上架/核查'
                this.categoryId = item.categoryId
                this.currentPage = 1
                this.pullUpLoad = false
                this.WeChatInit()
                this.getSearchData()
            } else {
                this.toast = this.$createToast({
                    txt: '请先选择超市！',
                    type: 'txt',
                    time: 1500
                }).show()
            }
        },
        // 微信扫一扫获取签名
        WeChatInit () {
            let url = location.href.split('#')[0]
            Axios.post('user/weixin/getSignature.do', {
                htmlUrl: url
            }).then(res => {
                if (res.respCode === 'S') {
                    wx.config({
                        debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
                        appId: res.data.appid, // 必填，公众号的唯一标识
                        timestamp: res.data.timestamp, // 必填，生成签名的时间戳
                        nonceStr: res.data.noncestr, // 必填，生成签名的随机串
                        signature: res.data.signature,// 必填，签名
                        jsApiList: ['scanQRCode'] // 必填，需要使用的JS接口列表
                    })
                }
            })
        },
        // 扫一扫
        WeChatScan () {
            let self = this
            if (!self.isWeChat()) {
                this.toast = this.$createToast({
                    txt: '扫一扫只能在微信中使用',
                    type: 'txt'
                })
                this.toast.show()
            }
            wx.ready(() => {
                wx.scanQRCode({
                    needResult: 1,
                    scanType: ["barCode"],
                    success: res => {
                        let key = res.resultStr
                        key = key.split(',')
                        key = key[1]
                        this.barcode = key
                        this.currentPage = 1
                        this.pullUpLoad = false
                        this.getSearchData()
                    }
                })
            })
            wx.error(res => {
                console.log(res.errMsg)
            })
        },
        // 判断当前是否在微信中打开
        isWeChat () {
            let ua = navigator.userAgent.toLowerCase()
            if(ua.match(/MicroMessenger/i)=="micromessenger") {
                return true
            } else {
                return false
            }
        },
        // 更改排序
        changeTab (index) {
            this.tabIndex = index
            this.currentPage = 1
            this.pullUpLoad = false
            if (index === 0) {
                this.orderType = 'AFFECTEDTIME_DOWN'
                this.$refs.goodsScroll.scrollTo(0, 0, 200, 'linear')
                this.getSearchData()
            } else if (index === 1) {
                if (this.orderType === 'AFFECTEDTIME_DOWN' || this.orderType === 'PRICE_DOWN' || this.orderType === 'SPREAD_DOWN') {
                    this.orderType = 'PRICE_UP'
                    this.$refs.goodsScroll.scrollTo(0, 0, 200, 'linear')
                    this.getSearchData()
                } else if (this.orderType === 'PRICE_UP') {
                    this.orderType = 'PRICE_DOWN'
                    this.$refs.goodsScroll.scrollTo(0, 0, 200, 'linear')
                    this.getSearchData()
                }
            } else if (index === 2) {
                this.orderType = 'SPREAD_DOWN'
                this.$refs.goodsScroll.scrollTo(0, 0, 200, 'linear')
                this.getSearchData()
            }
        },
        // 搜索无限加载
        searchMore() {
            this.currentPage ++
            if(this.currentPage > this.totalPage){
                this.$refs.goodsScroll.forceUpdate()
                return
            }
            this.getSearchData()
        },
        // 搜索获取数据
        getSearchData () {
            let data = {}
            if (this.barcode) {
                data = {
                    supermarketId: this.market.supermarketId,
                    orderBy: this.orderType,
                    currentPage: this.currentPage,
                    pageSize: this.pageSize,
                    barcode: this.barcode
                }
            } else {
                data = {
                    supermarketId: this.market.supermarketId,
                    categoryId: this.categoryId,
                    orderBy: this.orderType,
                    currentPage: this.currentPage,
                    pageSize: this.pageSize,
                    fullName: this.key
                }
            }
            Axios.post('goods/goods/checkPrices.do', data).then(res => {
                if (res.respCode === 'S') {
                    this.barcode = ''
                    let list = res.data.data
                    list.forEach(item => {
                        if (item.goodsPrice) {
                            item.goodsPrice = '￥' + Number(item.goodsPrice) / 100
                            item.btnText = '价格纠错'
                        } else {
                            item.goodsPrice = '暂无价格'
                            item.btnText = '价格分享'
                        }
                        if (item.spreadRate) {
                            item.spreadRate = item.spreadRate + '%'
                        } else {
                            item.spreadRate = '0%'
                        }
                        item.royaltyAmount = Number(item.royaltyAmount) / 100
                    })
                    if (this.currentPage === 1) {
                        this.searchData = list
                    } else {
                        this.searchData = this.searchData.concat(list)
                    }
                    this.totalPage = res.data.totalPage
                    if (this.currentPage < this.totalPage) {
                        this.pullUpLoad = true
                    }
                } else {
                    this.toast = this.$createToast({
                        txt: res.errorMsg,
                        type: 'txt'
                    })
                    this.toast.show()
                    this.$refs.goodsScroll.forceUpdate()
                }
            })
        },
        // 搜索框提交
        keySearch (event) {
            if (event.keyCode == 13) { //如果按的是enter键 13是enter
                this.currentPage = 1
                this.pullUpLoad = false
                this.getSearchData()
                this.$nextTick(() => {
                    this.$refs.goodsScroll.scrollTo(0, 0)
                    this.$refs.goodsScroll.refresh()
                })
            }
        },
        // 点击有偿上架
        btnUpperShelf () {
            this.showType = 3
            this.headerTitle = '有偿上架'
        },
        // 有偿上架选择价格类型
        choicePriceType () {
            this.$createActionSheet({
                data: [
                    {
                        content: '正常价'
                    },
                    {
                        content: '促销价'
                    },
                    {
                        content: '处理价'
                    },
                    {
                        content: '会员价'
                    }
                ],
                onSelect: (item, index) => {
                    this.upperShelfParams.priceType = item.content
                },
                onCancel: () => {

                }
            }).show()
        },
        // 开始时间和结束时间弹窗弹出
        choiceStartAndEndTime () {
            this.startAndEndTime()
            this.startAndEndTimePicker.show()
        },
        // 开始时间和结束时间弹窗初始化
        startAndEndTime () {
            let dateSegmentData = [
                {
                    is: 'cube-date-picker',
                    title: '开始时间',
                    min: new Date(),
                    max: new Date(2030, 12, 31, 23, 59),
                    columnCount: 5
                },
                {
                    is: 'cube-date-picker',
                    title: '结束时间',
                    min: new Date(),
                    max: new Date(2030, 12, 31, 23, 59),
                    columnCount: 5
                }
            ]
            this.startAndEndTimePicker = this.$createSegmentPicker({
                data: dateSegmentData,
                onSelect: (selectedDates, selectedVals, selectedTexts) => {
                    let startTime = selectedTexts[0]
                    let endTime = selectedTexts[1]
                    this.upperShelfParams.startTime = startTime[0] + '-' + startTime[1] + '-' + startTime[2] + ' ' + startTime[3] + ':' + startTime[4]
                    this.upperShelfParams.endTime = endTime[0] + '-' + endTime[1] + '-' + endTime[2] + ' ' + endTime[3] + ':' + endTime[4]
                },
                onNext: (i, selectedDate, selectedValue, selectedText) => {
                    dateSegmentData[1].min = selectedDate
                    if (i === 0) {
                        this.startAndEndTimePicker.$updateProps({
                            data: dateSegmentData
                        })
                    }
                }
            })
        },
        // 图片预览
        upperShelfShowImage() {
            let self = this
            let inputDOM = this.$refs.uploadFile;
            // 通过DOM取文件数据
            this.upperShelfParams.file = inputDOM.files[0];
            var reader = new FileReader();
            reader.onload = function (evt) {
                var srcString = evt.target.result;
                //安卓获取的base64数据无信息头，加之
                if (srcString.substring(5, 10) != "image") {
                    srcString = srcString.replace(/(.{5})/, "$1image/jpeg;");
                }
                self.imageSrc = srcString;
            }
            if (self.upperShelfParams.file) {
                reader.readAsDataURL(self.upperShelfParams.file);
            }
        },
        // 验证有偿上架数据是否合法
        btnUpperShelfCheckParam() {
            let data = this.upperShelfParams
            for (let i in data) {
                if (i === 'priceType') {
                    if (data[i] === '请选择价格类型' || data[i] === '') {
                        this.toast = this.$createToast({
                            txt: '请填写所有项',
                            type: 'txt'
                        })
                        this.toast.show()
                        return false
                    }
                } else if (i === 'startTime') {
                    if (data[i] === '请选择开始时间' || data[i] === '') {
                        this.toast = this.$createToast({
                            txt: '请填写所有项',
                            type: 'txt'
                        })
                        this.toast.show()
                        return false
                    }
                } else if (i === 'endTime') {
                    if (data[i] === '请选择结束时间' || data[i] === '') {
                        this.toast = this.$createToast({
                            txt: '请填写所有项',
                            type: 'txt'
                        })
                        this.toast.show()
                        return false
                    }
                } else {
                    if (data[i] === '') {
                        this.toast = this.$createToast({
                            txt: '请填写所有项',
                            type: 'txt'
                        })
                        this.toast.show()
                        return false
                    }
                }
            }
            return true
        },
        // 有偿上架提交
        btnUpperShelfSumbit () {
            let data = this.upperShelfParams
            this.btnDisabled = true

            data.price = Math.round(this.showPrice * 100)
            data.supermarketId = this.market.supermarketId
            data.categoryId = this.categoryId
            let param = new FormData()
            if (this.btnUpperShelfCheckParam()) {
                for (let i in data) {
                    if (i === 'priceType') {
                        if (data[i] === '正常价') {
                            param.append(i, 'NORMAL')
                        } else if (data[i] === '促销价') {
                            param.append(i, 'PROMOTION')
                        } else if (data[i] === '处理价') {
                            param.append(i, 'DEAL')
                        } else if (data[i] === '会员价') {
                            param.append(i, 'MEMBER')
                        }
                    } else {
                        param.append(i, data[i])
                    }
                }
            } else {
                this.btnDisabled = false
                return
            }
            Axios.post('goods/goods/insert.do', param).then(res => {
                if (res.respCode === 'S') {
                    this.toast = this.$createToast({
                        txt: res.data,
                        type: 'txt',
                        time: 1000
                    }).show()
                    setTimeout(() => {
                        this.currentPage = 1
                        this.pullUpLoad = false
                        this.getSearchData()
                        this.btnDisabled = false
                        this.showType = 1
                        this.headerTitle = '商品上架/核查'
                        this.upperShelfInitialize()
                    }, 1000)
                } else {
                    this.toast = this.$createToast({
                        txt: res.errorMsg,
                        type: 'txt',
                        time: 1000
                    }).show()
                    this.btnDisabled = false
                }
            })
        },
        // 有偿上架参数初始化
        upperShelfInitialize () {
            this.showPrice = null
            this.imageSrc = null
            this.btnDisabled = false
            this.upperShelfParams = {
                name: '',
                brand: '',
                price: '',
                specification: '',
                description: '',
                barcode: '',
                priceType: '请选择价格类型',
                startTime: '请选择开始时间',
                endTime: '请选择结束时间',
                file: ''
            }
        },
        // 点击价格纠错
        btnCorrection (item) {
            this.params.goodsSkuId = item.goodsSkuId
            this.params.supermarketId = this.market.supermarketId
            this.correctionGoods.image = item.image
            this.correctionGoods.name = item.fullName
            this.correctionGoods.price = item.goodsPrice
            this.correctionGoods.royaltyAmount = item.royaltyAmount
            this.correctionGoods.barcode = item.barcode
            this.showType = 2
            this.headerTitle = '价格纠错'
        },
        // 价格纠错选择价格类型
        changePriceType () {
            this.$createActionSheet({
                data: [
                    {
                        content: '正常价'
                    },
                    {
                        content: '促销价'
                    },
                    {
                        content: '处理价'
                    },
                    {
                        content: '会员价'
                    }
                ],
                onSelect: (item, index) => {
                    this.params.priceType = item.content
                },
                onCancel: () => {

                }
            }).show()
        },
        // 价格纠错开始时间和结束时间弹窗弹出
        changeStartAndEndTime () {
            this.correctionStartAndEndTime()
            this.startAndEndTimePicker.show()
        },
        // 价格纠错开始时间和结束时间弹窗初始化
        correctionStartAndEndTime () {
            let dateSegmentData = [
                {
                    is: 'cube-date-picker',
                    title: '开始时间',
                    min: new Date(),
                    max: new Date(2030, 12, 31, 23, 59),
                    columnCount: 5
                },
                {
                    is: 'cube-date-picker',
                    title: '结束时间',
                    min: new Date(),
                    max: new Date(2030, 12, 31, 23, 59),
                    columnCount: 5
                }
            ]
            this.startAndEndTimePicker = this.$createSegmentPicker({
                data: dateSegmentData,
                onSelect: (selectedDates, selectedVals, selectedTexts) => {
                    let startTime = selectedTexts[0]
                    let endTime = selectedTexts[1]
                    this.params.startTime = startTime[0] + '-' + startTime[1] + '-' + startTime[2] + ' ' + startTime[3] + ':' + startTime[4]
                    this.params.endTime = endTime[0] + '-' + endTime[1] + '-' + endTime[2] + ' ' + endTime[3] + ':' + endTime[4]
                },
                onNext: (i, selectedDate, selectedValue, selectedText) => {
                    dateSegmentData[1].min = selectedDate
                    if (i === 0) {
                        this.startAndEndTimePicker.$updateProps({
                            data: dateSegmentData
                        })
                    }
                }
            })
        },
        // 价格纠错图片预览
        showImage() {
            let self = this
            let inputDOM = this.$refs.correctionUploadFile;
            // 通过DOM取文件数据
            this.params.file = inputDOM.files[0];
            var reader = new FileReader();
            reader.onload = function (evt) {
                var srcString = evt.target.result;
                //安卓获取的base64数据无信息头，加之
                if (srcString.substring(5, 10) != "image") {
                    srcString = srcString.replace(/(.{5})/, "$1image/jpeg;");
                }
                self.imageSrc = srcString;
            }
            if (self.params.file) {
                reader.readAsDataURL(self.params.file);
            }
        },
        // 验证价格纠错数据是否合法
        CheckParam() {
            let data = this.params
            for (let i in data) {
                if (i === 'priceType') {
                    if (data[i] === '请选择价格类型' || data[i] === '') {
                        this.toast = this.$createToast({
                            txt: '请填写所有项',
                            type: 'txt'
                        })
                        this.toast.show()
                        return false
                    }
                } else if (i === 'startTime') {
                    if (data[i] === '请选择开始时间' || data[i] === '') {
                        this.toast = this.$createToast({
                            txt: '请填写所有项',
                            type: 'txt'
                        })
                        this.toast.show()
                        return false
                    }
                } else if (i === 'endTime') {
                    if (data[i] === '请选择结束时间' || data[i] === '') {
                        this.toast = this.$createToast({
                            txt: '请填写所有项',
                            type: 'txt'
                        })
                        this.toast.show()
                        return false
                    }
                } else {
                    if (data[i] === '') {
                        this.toast = this.$createToast({
                            txt: '请填写所有项',
                            type: 'txt'
                        })
                        this.toast.show()
                        return false
                    }
                }
            }
            return true
        },
        // 价格纠错提交
        correctionSumbit () {
            if (this.showPrice === this.correctionGoods) {
                this.toast = this.$createToast({
                    txt: '您输入的价格和已生效的价格相同！',
                    type: 'txt',
                    time: 1000
                }).show()
                return
            }
            let data = this.params
            this.btnDisabled = true

            data.price = Math.round(this.showPrice * 100)
            let param = new FormData()
            if (this.CheckParam()) {
                for (let i in data) {
                    if (i === 'priceType') {
                        if (data[i] === '正常价') {
                            param.append(i, 'NORMAL')
                        } else if (data[i] === '促销价') {
                            param.append(i, 'PROMOTION')
                        } else if (data[i] === '处理价') {
                            param.append(i, 'DEAL')
                        } else if (data[i] === '会员价') {
                            param.append(i, 'MEMBER')
                        }
                    } else {
                        param.append(i, data[i])
                    }
                }
            } else {
                this.btnDisabled = false
                return
            }
            Axios.post('correct/correct/currencyUpdatePrice.do', param).then(res => {
                if (res.respCode === 'S') {
                    this.toast = this.$createToast({
                        txt: res.data,
                        type: 'txt',
                        time: 1000
                    }).show()
                    setTimeout(() => {
                        this.currentPage = 1
                        this.pullUpLoad = false
                        this.getSearchData()
                        this.btnDisabled = false
                        this.showType = 1
                        this.headerTitle = '商品上架/核查'
                        this.correctionInitialize()
                    }, 1000)
                } else {
                    this.toast = this.$createToast({
                        txt: res.errorMsg,
                        type: 'txt'
                    })
                    this.toast.show()
                    this.btnDisabled = false
                }
            })
        },
        // 价格纠错参数初始化
        correctionInitialize () {
            this.showPrice = null
            this.imageSrc = null
            this.btnDisabled = false
            this.params = {
                supermarketId: '',
                goodsSkuId: '',
                price: '',
                priceType: '请选择价格类型',
                startTime: '请选择开始时间',
                endTime: '请选择结束时间'
            }
        },
        goHistory () {
            this.currentPage = 1
            this.pullUpLoad = false
            this.getUpperShelfHistoryData()
            this.showType = 4
            this.headerTitle = '历史'
            this.historyTabLabel = '有偿上架'
        },
        historyHandler (label) {
            this.historyTabLabel = label
        },
        changeHistoryTab (index) {
            this.currentPage = 1
            this.pullUpLoad = false
            if (index === 0) {
                this.$refs.upperShelfHistory.scrollTo(0, 0)
                this.getUpperShelfHistoryData()
            } else if (index === 1) {
                this.$refs.correctionHistory.scrollTo(0, 0)
                this.getCorrectionHistoryData()
            }
            this.historyTabLabel = this.historyTab[index].label
        },
        correctionHistoryMore () {
            this.currentPage ++
            if(this.currentPage > this.totalPage){
                this.$refs.correctionHistory.forceUpdate()
                return
            }
            this.getCorrectionHistoryData()
        },
        getCorrectionHistoryData () {
            Axios.post('correct/correct/historyForCorrect.do', {
                correctWay: 'CHECKPRICE',
                supermarketId: this.historyMarket.supermarketId,
                createTimeStart: this.startTime,
                createTimeEnd: this.endTime,
                currentPage: this.currentPage,
                pageSize: this.pageSize
            }).then(res => {
                if (res.respCode === 'S') {
                    let list = res.data.data
                    list.forEach(item => {
                        item.createTime = new Date(item.createTime).Format('yy/MM/dd')
                        item.price = '￥' + Number(item.price) / 100
                        item.royaltyAmount = Number(item.royaltyAmount) / 100
                        switch (item.status) {
                            case 'AFFECTED':
                            item.status = '完成'
                            break
                            case 'RECALL':
                            item.status = '失败'
                            break
                            case 'WAIT_AUDIT':
                            item.status = '审核中'
                            break
                            case 'AUDIT_SUCCESS':
                            item.status = '审核中'
                            break
                            case 'AUDIT_FAIL':
                            item.status = '失败'
                            break
                            case 'EXPIRED':
                            item.status = '完成'
                            break
                        }
                    })
                    if (this.currentPage === 1) {
                        this.correctionHistoryData = list
                    } else {
                        this.correctionHistoryData = this.correctionHistoryData.concat(list)
                    }
                    this.totalPage = res.data.totalPage
                    if (this.currentPage < this.totalPage) {
                        this.pullUpLoad = true
                    }
                }
            })
        },
        upperShelfHistoryMore () {
            this.currentPage ++
            if(this.currentPage > this.totalPage){
                this.$refs.upperShelfHistory.forceUpdate()
                return
            }
            this.getUpperShelfHistoryData()
        },
        getUpperShelfHistoryData () {
            Axios.post('goods/goods/selectHistory.do', {
                supermarketId: this.historyMarket.supermarketId,
                createTime: this.startTime,
                updateTime: this.endTime,
                currentPage: this.currentPage,
                pageSize: this.pageSize
            }).then(res => {
                if (res.respCode === 'S') {
                    let list = res.data.data
                    list.forEach(item => {
                        item.createTime = new Date(item.createTime).Format('yy/MM/dd')
                        item.price = '￥' + Number(item.price) / 100
                        switch (item.status) {
                            case 'AUDIT_SUCCESS':
                            item.status = '完成'
                            break
                            case 'AUDIT_FAIL':
                            item.status = '失败'
                            break
                            case 'WAIT_AUDIT':
                            item.status = '审核中'
                            break
                        }
                    })
                    if (this.currentPage === 1) {
                        this.upperShelfHistoryData = list
                    } else {
                        this.upperShelfHistoryData = this.upperShelfHistoryData.concat(list)
                    }
                    this.totalPage = res.data.totalPage
                    if (this.currentPage < this.totalPage) {
                        this.pullUpLoad = true
                    }
                }
            })
        },
        historyScreen () {
            this.historyScreenTime()
            this.screenTimePicker.show()
        },
        // 价格纠错开始时间和结束时间弹窗初始化
        historyScreenTime () {
            let dateSegmentData = [
                {
                    is: 'cube-date-picker',
                    title: '开始时间',
                    min: new Date(2019, 0, 1),
                    max: new Date(2030, 12, 31),
                    columnCount: 3
                },
                {
                    is: 'cube-date-picker',
                    title: '结束时间',
                    min: new Date(2019, 0, 1),
                    max: new Date(2030, 12, 31),
                    columnCount: 3
                }
            ]
            this.screenTimePicker = this.$createSegmentPicker({
                data: dateSegmentData,
                onSelect: (selectedDates, selectedVals, selectedTexts) => {
                    let startTime = selectedTexts[0]
                    let endTime = selectedTexts[1]
                    this.startTime = startTime[0] + '-' + startTime[1] + '-' + startTime[2] + ' 00:00:00'
                    this.endTime = endTime[0] + '-' + endTime[1] + '-' + endTime[2] + ' 23:59:59'
                    this.currentPage = 1
                    this.pullUpLoad = false
                    if (this.historyTabLabel === '有偿上架') {
                        this.$refs.upperShelfHistory.scrollTo(0, 0)
                        this.getUpperShelfHistoryData()
                    } else if (this.historyTabLabel === '分享纠错') {
                        this.$refs.correctionHistory.scrollTo(0, 0)
                        this.getCorrectionHistoryData()
                    }
                },
                onNext: (i, selectedDate, selectedValue, selectedText) => {
                    dateSegmentData[1].min = selectedDate
                    if (i === 0) {
                        this.screenTimePicker.$updateProps({
                            data: dateSegmentData
                        })
                    }
                }
            })
        }
    }
})
